<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created: August 17, 2001-->
<!--
$Id: RepLocation.php,v 1.7 2001/11/02 19:08:19 eugenem Exp $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/RepLocation.php,v 1.7 2001/11/02 19:08:19 eugenem Exp $
$Log: RepLocation.php,v $
Revision 1.7  2001/11/02 19:08:19  eugenem
Moved HTTP_*_VARS processing to dbc.inc

Revision 1.6  2001/11/02 14:59:03  eugenem
Moved database connect statements to a separate file.

Revision 1.5  2001/10/23 19:12:52  eugenem
Added Add Survey button for each machine displayed.

Revision 1.4  2001/10/23 17:45:46  eugenem
Made the Description column a link to RepMachine.php to display machine info.

Revision 1.3  2001/08/20 15:39:26  eugenem
Move $sortby processing outside query generation loop.

Revision 1.2  2001/08/17 18:34:39  eugenem
Sort output into different tables grouped by location

Revision 1.1  2001/08/17 14:58:02  eugenem
Initial revision

-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah" />
<link rev="made" href="mailto:eugenem@ix.netcom.com" />
<link rev="home" href="http://blog.imabug.net/" />
<meta name="description" content="" />
<meta name="Keywords" content="" />
<meta name="Reply-to" content="eugenem@ix.netcom.com" />
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))' />
<?PHP
require('functions.inc');
require('dbc.inc');

?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<h2>List Equipment by Location</h2>
<?PHP
if (isset($locID)) {
  $orderby = "";

  if (!empty($sortby)) {
    $orderby = "ORDER BY ";
    while (list($name,$id) = each($sortby)) {
      $orderby .= "$id,";
    }
    $orderby = substr($orderby,0,-1);  // Trim the last comma
  }

  while (list($name,$id) = each($locID)) {
    $row = mysql_fetch_array(mysql_query("select Location from Location where LocationID=$id"));
    $loc = $row['Location'];

    $query = "SELECT MachineID,Modality,Manufacturer,Model,SerialNumber,Description,Location,Room,
            IF(ManufDate<>\"0000-00-00\",PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM ManufDate)),
        IF(InstallDate<>\"0000-00-00\",PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM InstallDate)),\"N/A\")) AS Age FROM 
        Modality,Manufacturer,Location,Machines WHERE 
        (Machines.LocationID=$id) AND 
        Status=\"Active\" AND 
        Modality.ModalityID=Machines.ModalityID AND 
        Manufacturer.ManufacturerID=Machines.ManufacturerID AND 
        Location.LocationID=Machines.LocationID ";
    $query .= $orderby;

    $result = mysql_query($query)
      or die ("Query failed: $query<br>\n");
?>
<h2><?PHP echo $loc; ?> (<?php echo mysql_num_rows($result) . " units"; ?>)</h2>
<table border=1>
  <tr>
    <th></th><th>ID</th><th>Modality</th><th>Manufacturer</th><th>Model</th><th>SN</th><th>Description</th><th>Location</th><th>Age</th><th>Last Survey</th>
  </tr>
<?PHP
    // Spit the results out into a table
    $i = 1;
    while ($row= mysql_fetch_array($result)) {
      // Get the most recent survey date for the current machine
      $query = "SELECT SurveyID,TestDate FROM TestDates WHERE MachineID=" . $row['MachineID'] . " AND ";
      $query .= "(TypeID=1 or TypeID=2) ";
      $query .= "ORDER BY TestDate DESC LIMIT 1";
      $surv_result = mysql_query($query);
      $surv_row = mysql_fetch_array($surv_result);
      echo "<tr>\n";
      echo "<td>" . $i . "</td>\n";
      echo "<td>" . $row['MachineID'] . "</td>\n";
      echo "<td>" . $row['Modality'] . "</td>\n";
      echo "<td>" . $row['Manufacturer'] . "</td>\n";
      echo "<td>" . $row['Model'] . "</td>\n";
      echo "<td>" . $row['SerialNumber'] . "</td>\n";
      echo "<td><a href=\"RepMachine.php?MachID=" . $row['MachineID'] . "\"> " . $row['Description'] . "</a></td>\n";
      echo "<td>" . $row['Room'] . "</td>\n";
      echo "<td>" . round($row['Age']/12,1) . "</td>\n";
      // Clicking on survey date takes user to the list of survey recommendations
      echo "<td><a href=\"SurveyResRec.php?SurveyID=" . $surv_row['SurveyID'] . "\">" . $surv_row['TestDate'] . "</a></td>";
      echo "<td>\n";
      echo "  <form action=\"SurveyAdd.php\" method=\"POST\">\n";
      echo "  <input type=\"HIDDEN\" name=\"MachID\" value=\"" . $row['MachineID'] . "\">\n";
      echo "  <input type=\"SUBMIT\" value=\"Add Survey\">\n";
      echo "  </form>\n";
      echo "</td>\n";
      echo "</tr>\n";
      $i++;
    }
?>
</table>
<?PHP
  }
}
?>

<form action="RepLocation.php" method="POST">
<p>Select Location:
<!--
locID is specified as an array to hold multiple SELECTions for processing 
-->
<select name="locID[]" size=4 MUlTIPLE>
<?PHP
$loc = mysql_query("select * from Location order by Location");
while (list($key,$val) = mysql_fetch_array($loc)) {
  echo "<option value=\"$key\">$val</option>\n";
}
?>
</select>
(Control or Shift click to select multiple modalities)
</p>
<p>
Sort results by: 
<input type="CHECKBOX" name="sortby[]" value="Modality">Modality</input>
<input type="CHECKBOX" name="sortby[]" value="Manufacturer">Manufacturer</input>
<input type="CHECKBOX" name="sortby[]" value="Model">Model</input>
<input type="CHECKBOX" name="sortby[]" value="Description">Description</input>
<input type="CHECKBOX" name="sortby[]" value="Location">Location</input>
</p>
<p><input type="SUBMIT" value="Search" /> / <input type="RESET" value="Reset" /> / <a href="index.html" target="_top" >Main</a></p>
</form>
</body>
</html>
